// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import HelloWorld from './components/HelloWorld'
import router from './router'
import element from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import VueRouter from 'vue-router';
import axios from 'axios'

import VueCookies from 'vue-cookies'    //引入VueCookies
Vue.use(VueCookies)
Vue.prototype.$vuecookies = VueCookies;
import echarts from 'echarts'
Vue.prototype.$echarts = echarts;

//this.$cookies.config(expireTimes, path)
Vue.config.productionTip = false
Vue.prototype.$axios = axios

//Vue.use(vuecookies)

const originalPush = VueRouter.prototype.push


VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)

}

router.beforeEach((to, from, next) => {
  if (to.matched.some(record => record.meta.requireAuth)){  // 判断该路由是否需要登录权限
   // console.log('需要登录');


  //this.$VueCookies.getCookie('token')
   // if (localStorage.token) {  // 判断当前的token是否存在 ； 登录存入的token
    if (VueCookies.isKey('token')) {  // 判断当前的token是否存在 ； 登录存入的token
    //  console.log(to);
    //   console.log(from);
    //   console.log("路径");
    //    console.log(next);
    // if (to.path === '/login') {
    // 　　　　
    // 　　　　　　router.push({ path: '/', });;
    // 　　　　
    // 　　}
     next();
    }
    else {
      next({
        path: '/login',
         query: {redirect: to.fullPath}  // 将跳转的路由path作为参数，登录成功后跳转到该路由
      })
    }
  }
  else {
    next();
  }
});


Vue.use(element)
Vue.use(VueRouter)
Vue.config.productionTip = false



/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>',
  // render: h=>h(HelloWorld),

  data:{
    quangjiu : 121,
  },
  methods:{

  }
})
